package com.zlsoft.web.utils.xpopup;

import android.app.Activity;
import android.text.TextUtils;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.SimpleCallback;
import com.zlsoft.web.constant.DynamicValue;
import com.zlsoft.web.popup.FirstInitPopup;
import com.zlsoft.web.sp.ConfigPreference;

/**
 * @author - qqz
 * @date - 2021-12-16/10:28
 * @note -
 * ---------------------------------------------------------------------------------------------------------------------------------
 * @modified -
 * @date -
 * @note -
 */
public class PopupUtils {

    private static PopupUtils mPopupUtils;

    public static PopupUtils getInstance() {
        if (mPopupUtils == null) {
            synchronized (PopupUtils.class) {
                if (mPopupUtils == null) {
                    mPopupUtils = new PopupUtils();
                }
            }
        }

        return mPopupUtils;
    }

    /**
     * activity
     *
     * @param mActivity
     * @param firstUse
     * @param mCallBack
     */
    public void firstLoad(Activity mActivity, boolean firstUse, OnCallBack mCallBack) {
        FirstInitPopup mFirstInitPopup = new FirstInitPopup(mActivity, firstUse);
        if (TextUtils.isEmpty(DynamicValue.getWebPath())) {
            new XPopup.Builder(mActivity)
                    .dismissOnBackPressed(false)
                    .setPopupCallback(new SimpleCallback() {
                        @Override
                        public void onDismiss(BasePopupView popupView) {
                            DynamicValue.setWebToken(FirstInitPopup.sSiteUrl);
                            if (mCallBack != null) {
                                mCallBack.onSucceed(true);
                            }
                        }
                    }).dismissOnTouchOutside(false).asCustom(mFirstInitPopup).show();

            // 首次使用触发
            mCallBack.onSucceed(false);

        } else {
            if (mCallBack != null) {
                mCallBack.onSucceed(true);
            }
        }
    }


    public interface OnCallBack {
        void onSucceed(boolean mB);
    }
}
